package com.medicine.hbp.ui;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.kymjs.kjframe.KJBitmap;
import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.BindView;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.medicine.hbp.adapter.BqianAdapter;
import com.medicine.hbp.base.BaseActivity;
import com.medicine.hbp.dialog.PhotographDialog;
import com.medicine.hbp.dialog.PhotographDialog.PhotographDialogListener;
import com.medicine.hbp.emotion.DisplayUtils;
import com.medicine.hbp.emotion.EmotionGvAdapter;
import com.medicine.hbp.emotion.EmotionPagerAdapter;
import com.medicine.hbp.emotion.EmotionUtils;
import com.medicine.hbp.emotion.StringUtils;
import com.medicine.hbp.http.AppHttpCallBack;
import com.medicine.hbp.http.AppHttps;
import com.medicine.hbp.http.HttpInterface;
import com.medicine.hbp.http.UploadUtil;
import com.medicine.hbp.http.UploadUtil.ImageCallBack;
import com.medicine.hbp.mob.FindLabersVo;
import com.medicine.hbp.mob.article;
import com.medicine.hbp.uitl.ChoosePicturesUtils;
import com.medicine.hbp.uitl.CommUtil;
import com.medicine.hbp.uitl.DisplayUtil;
import com.medicine.hbp.uitl.ToastUtil;
import com.medicine.hbp.R;

/**
 * 发布
 * @author jindandan
 */
public class ReleaseActivity extends BaseActivity implements
		OnItemClickListener {
	@BindView(id = R.id.btn_image_left_exit, click = true)public ImageView btn_image_left_exit;
	@BindView(id = R.id.text_title)public TextView text_title;
	@BindView(id = R.id.btn_image_right, click = true)public Button btn_image_right;

	@BindView(id = R.id.image_photo, click = true)public ImageView image_photo;
	@BindView(id = R.id.image_ww, click = true)public ImageView image_ww;
	@BindView(id = R.id.image_bqtype, click = true)public ImageView image_bqtype;
	@BindView(id = R.id.et_title, click = true)public EditText et_title;
	@BindView(id = R.id.edit_context, click = true)public EditText edit_context;
	@BindView(id = R.id.grid_bqtype)public GridView grid_bqtype;
	@BindView(id = R.id.text_biaoq)public TextView text_biaoq;
	@BindView(id = R.id.release_layout)public LinearLayout release_layout;
	@BindView(id = R.id.radio, click = true)public LinearLayout radio;
	@BindView(id = R.id.img_radio)public ImageView img_radio;
	private boolean Bradio=false;


	private EditText isEditText=null;


	private BqianAdapter adapter=null;
	private EmotionPagerAdapter emotionPagerGvAdapter;
	@BindView(id = R.id.vp_emotion_dashboard)
	public ViewPager vp_emotion_dashboard;
	@BindView(id = R.id.ll_emotion_dashboard)
	public LinearLayout ll_emotion_dashboard;
	@BindView(id = R.id.ll_add_image)
	public LinearLayout ll_add_image;//图片添加
	@BindView(id = R.id.ll_photo_bq)
	public LinearLayout ll_photo_bq;//整体表情和照片选择

	public String labers="";
	public List<String> listUrl=new ArrayList<String>();

	private boolean isbtnRight=true;
	public FindLabersVo results=null;
	private Bitmap imagebitmap;
	private AppDialog dialog;
	@Override
	public void setRootView() {
		super.setRootView();
		setContentView(R.layout.activity_release);
	}
	public List<RekeaseBase> listBase;
	public RekeaseBase baseEdit;
	public RekeaseBase baseUrl;
	@Override
	public void initWidget() {
		super.initWidget();
		initEmotion();
		edit_context.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View arg0, boolean arg1) {
				isEditText=edit_context;
			}
		});
		et_title.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View arg0, boolean arg1) {
				isEditText=et_title;
//				ll_emotion_dashboard.setVisibility(View.GONE);
			}
		});
		release_layout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			@Override
			public void onGlobalLayout() {
				//比较Activity根布局与当前布局的大小
				int heightDiff = release_layout.getRootView().getHeight()- release_layout.getHeight();
				if(heightDiff >100){
					//大小超过100时，一般为显示虚拟键盘事件
//		        	if(!(ll_emotion_dashboard.getVisibility()==View.GONE)){
//		        		ll_emotion_dashboard.setVisibility(View.GONE);
//		        	}

				}else{
					//大小小于100时，为不显示虚拟键盘或虚拟键盘隐藏
				}

			}
		});
		dialog=new AppDialog(this);
//		text_title.setText("我要投稿");
		text_title.setText("");
		btn_image_left_exit.setVisibility(View.VISIBLE);
		btn_image_right.setBackgroundColor(R.color.transparent);
		baseEdit=new RekeaseBase();
		baseUrl=new RekeaseBase();
		listBase=new ArrayList<ReleaseActivity.RekeaseBase>();
		btn_image_left_exit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();

			}
		});
	}

	@Override
	public void widgetClick(View v) {
		super.widgetClick(v);
		switch (v.getId()) {
			case R.id.image_photo:
				startPhotographDialog();
				break;
			case R.id.radio:
				if(Bradio){
					Bradio=false;
					img_radio.setImageResource(R.mipmap.radio_no);
				}else{
					Bradio=true;
					img_radio.setImageResource(R.mipmap.radio_yes);
				}
				break;
			case R.id.image_bqtype:
//			if(results!=null){
//				setAdapter(results);
//			}else{
//				httpFindLabers();
//			}
				Intent intent=new Intent(aty,LabelSelectActivity.class);
				intent.putExtra("id", labers);
				startActivityForResult(intent, 1000);
				break;
			case R.id.image_ww:
				stopIm();
				break;
			case R.id.btn_image_right:
				if(isbtnRight){//订单提交
					httpAddArtSubmit();
				}else{
					if(adapter.getLaberVos().size()==0){
						ToastUtil.showShort(aty,"未选择标签");
						return;
					}else{
						String bq="";
						for (int i = 0; i <adapter.getLaberVos().size(); i++) {
							if(adapter.getLaberVos().get(i).laderBoolean==true){
								bq+=adapter.getLaberVos().get(i).laberName+",";
							}
						}
						if(TextUtils.isEmpty(bq)){
							ToastUtil.showShort(aty, "你还没有选择标签");
							return;
						}
						text_biaoq.setVisibility(View.VISIBLE);
						text_biaoq.setText("已选择标签:"+bq.substring(0, bq.length()-1));
						isbtnRight=true;
						image_bqtype.setVisibility(View.VISIBLE);
						image_bqtype.setImageDrawable(getResources().getDrawable(R.mipmap.biaoqian_backgroud2));
						grid_bqtype.setVisibility(View.GONE);
						btn_image_right.setText("提交");
					}
				}
				break;
			case R.id.btn_image_left_exit:
				finish();
				break;
		}

	}
	/**
	 * 调用相机拍照选择
	 */
	private void startPhotographDialog() {
		PhotographDialog photographDialog = new PhotographDialog(aty,
				new PhotographDialogListener() {
					@Override
					public void onSelect(int position) {
						if (position == 0) {
							ChoosePicturesUtils.photographic(aty);
						} else {
							ChoosePicturesUtils.pickPhonoImage(aty);
						}
					}
					@Override
					public void onCancel() {
					}
				}, 0);
		photographDialog.showPhotographDialog();
	}

	/**
	 * 初始化表情面板内容
	 */
	private void initEmotion() {
		// 获取屏幕宽度
		int gvWidth = DisplayUtils.getScreenWidthPixels(this);
		// 表情边距
		int spacing = DisplayUtils.dp2px(this, 8);
		// GridView中item的宽度
		int itemWidth = (gvWidth - spacing * 8) / 7;
		int gvHeight = itemWidth * 3 + spacing * 4;

		List<GridView> gvs = new ArrayList<GridView>();
		List<String> emotionNames = new ArrayList<String>();
		// 遍历所有的表情名字
		for (String emojiName : EmotionUtils.emojiMap.keySet()) {
			emotionNames.add(emojiName);
			// 每20个表情作为一组,同时添加到ViewPager对应的view集合中
			if (emotionNames.size() == 20) {
				GridView gv = createEmotionGridView(emotionNames, gvWidth,
						spacing, itemWidth, gvHeight);
				gvs.add(gv);
				// 添加完一组表情,重新创建一个表情名字集合
				emotionNames = new ArrayList<String>();
			}
		}

		// 检查最后是否有不足20个表情的剩余情况
		if (emotionNames.size() > 0) {
			GridView gv = createEmotionGridView(emotionNames, gvWidth, spacing,
					itemWidth, gvHeight);
			gvs.add(gv);
		}

		// 将多个GridView添加显示到ViewPager中
		emotionPagerGvAdapter = new EmotionPagerAdapter(gvs);
		vp_emotion_dashboard.setAdapter(emotionPagerGvAdapter);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				gvWidth, gvHeight);
		vp_emotion_dashboard.setLayoutParams(params);
	}

	/**
	 * 创建显示表情的GridView
	 */
	private GridView createEmotionGridView(List<String> emotionNames,
										   int gvWidth, int padding, int itemWidth, int gvHeight) {
		// 创建GridView
		GridView gv = new GridView(this);
		gv.setBackgroundColor(Color.rgb(233, 233, 233));
		gv.setSelector(android.R.color.transparent);
		gv.setNumColumns(7);
		gv.setPadding(padding, padding, padding, padding);
		gv.setHorizontalSpacing(padding);
		gv.setVerticalSpacing(padding);
		LayoutParams params = new LayoutParams(gvWidth, gvHeight);
		gv.setLayoutParams(params);
		// 给GridView设置表情图片
		EmotionGvAdapter adapter = new EmotionGvAdapter(this, emotionNames,
				itemWidth);
		gv.setAdapter(adapter);
		gv.setOnItemClickListener(this);
		return gv;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
							long id) {
		if(isEditText==et_title||null==isEditText){
			return;
		}
		Object itemAdapter = parent.getAdapter();

		if (itemAdapter instanceof EmotionGvAdapter) {
			// 点击的是表情
			EmotionGvAdapter emotionGvAdapter = (EmotionGvAdapter) itemAdapter;

			if (position == emotionGvAdapter.getCount() - 1) {
				// 如果点击了最后一个回退按钮,则调用删除键事件
				isEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
						KeyEvent.KEYCODE_DEL));
			} else {
				// 如果点击了表情,则添加到输入框中
				String emotionName = emotionGvAdapter.getItem(position);

				// 获取当前光标位置,在指定位置上添加表情图片文本
				int curPosition = isEditText.getSelectionStart();
				StringBuilder sb = new StringBuilder(isEditText.getText()
						.toString());
				sb.insert(curPosition, emotionName);

				// 特殊文字处理,将表情等转换一下
				isEditText.setText(StringUtils.getEmotionContent(this, isEditText,
						sb.toString()));
				// 将光标设置到新增完表情的右侧
				isEditText.setSelection(curPosition + emotionName.length());
			}

		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (resultCode) {
			case RESULT_OK:
				if(requestCode==1000){
					text_biaoq.setVisibility(View.VISIBLE);
					text_biaoq.setText("已选择标签:"+data.getStringExtra("bq"));
					labers=data.getStringExtra("bqid");
					isbtnRight=true;
					image_bqtype.setVisibility(View.VISIBLE);
					image_bqtype.setImageDrawable(getResources().getDrawable(R.mipmap.biaoqian_backgroud2));
					grid_bqtype.setVisibility(View.GONE);
					btn_image_right.setText("提交");
				}
				// 存储卡可用
				if (ChoosePicturesUtils.isHasSdcard()) {
					if (requestCode == ChoosePicturesUtils.REQUEST_CODE_TAKE_PICTURE) {// 拍照返回
						if (!TextUtils.isEmpty(ChoosePicturesUtils.imagePathString)) {
							dialog.showDialog();
							imageThrred(ChoosePicturesUtils.imagePathString);
						}
					} else if (ChoosePicturesUtils.PHOTOZOOM == requestCode) {
						try {
							Uri uri = data.getData();
							if (uri != null) {
								String path = CommUtil.getImageAbsolutePath(aty,
										uri);
								if (!TextUtils.isEmpty(path)) {
									dialog.showDialog();
									imageThrred(path);
								} else {
									ToastUtil.showShort(aty, "从相册中选取照片失败");
								}
							}
						} catch (Exception e) {
							Log.e("ReleaseActivity", e.getMessage());
							e.printStackTrace();
						} finally {
						}
					}
				}
				break;
			default:
				break;
		}
	}
	private void imageThrred(final String path) {
		new Thread(new Runnable() {
			@Override
			public void run() {
//				httpFile(CommUtil.qrcodeMyBitmap(CommUtil.getimage(path), aty));
				httpFile(CommUtil.qrcodeMyBitmap(CommUtil.imageZoom(BitmapFactory.decodeFile(path)), aty));
			}
		}).start();
	}
	class RekeaseBase {
		//1:edit 2:imageurl
		public int type;
		public EditText editText;
		public String url;
	}
	/**
	 * 文件上传
	 * @param file
	 */
	private void httpFile(final String file) {
		UploadUtil.uploadFile(new File(file), AppHttps.HTTP_URL+HttpInterface.UPLOAD_FILE,new ImageCallBack() {
			@Override
			public void onSuccess(String url) {
				listUrl.add(url);
//						ToastUtil.showShort(aty, url);
				ImageView imageview=new ImageView(aty);
				imagebitmap=BitmapFactory.decodeFile(file);
				int Height=(int)(((float)(getWindow().getDecorView().getWidth()-DisplayUtil.dip2px(aty, 40))/(float)imagebitmap.getWidth())*imagebitmap.getHeight());
				LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, Height);
				imageview.setPadding(DisplayUtil.dip2px(aty, (float) 20.0), DisplayUtil.dip2px(aty, (float) 10.0), DisplayUtil.dip2px(aty, (float) 20.0),DisplayUtil.dip2px(aty, (float) 10.0));
				imageview.setLayoutParams(params);
				imageview.setScaleType(ScaleType.FIT_XY);
				KJBitmap bitmap=new KJBitmap();
				View view2=new View(aty);
				LayoutParams params2 = new LayoutParams(LayoutParams.MATCH_PARENT, 20);
				view2.setLayoutParams(params2);
				imageview.setImageBitmap(imagebitmap);
//						bitmap.display(imageview, url);
				ll_add_image.addView(imageview);
				ll_add_image.addView(view2);
				baseUrl.type=2;
				baseUrl.editText=null;
				baseUrl.url="[img_src="+url+"]";
				listBase.add(baseUrl);
				baseEdit.type=1;
				baseEdit.editText=initEditText();
				baseEdit.url=null;
				ll_add_image.addView(baseEdit.editText);
				listBase.add(baseEdit);

				if(imagebitmap!=null&&imagebitmap.isRecycled()){
					imagebitmap.recycle();
					imagebitmap=null;
				}
				dialog.dismissDialog();
			}

			@Override
			public void onFailure(String error) {
				ToastUtil.showShort(aty, error);
			}
		});

	}
	private EditText initEditText() {
		final EditText editText2=new EditText(aty);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		editText2.setLayoutParams(params);
		editText2.setPadding( DisplayUtil.dip2px(aty,(float) 20.0),0, DisplayUtil.dip2px(aty, (float) 20.0),0);
		editText2.setBackgroundColor(android.R.color.white);
		editText2.setTextColor(R.color.edit_text_one);
		editText2.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean isboolean) {
				if(isboolean){
					isEditText=editText2;
				}
			}
		});
		return editText2;
	}

	//	/**
//	 * 标签获取
//	 *
//	 * @param file
//	 */
//	private void httpFindLabers() {
//		HttpParams params = new HttpParams();
//		AppHttps.HttpPost(this,HttpInterface.FIND_LABERS, params,
//				new AppHttpCallBack<FindLabersVo>(FindLabersVo.class, aty) {
//					@Override
//					public void onSuccess(FindLabersVo result) {
//						if(result!=null){
//							results=result;
//							setAdapter(results);
//						}
//					}
//					@Override
//					public void onFailures(int errorCode, String errorMsg) {
//						ToastUtil.showShort(aty, errorMsg);
//
//					}
//				});
//	}
	public void setAdapter(FindLabersVo result) {
		image_bqtype.setVisibility(View.GONE);
		grid_bqtype.setVisibility(View.VISIBLE);
		adapter = new BqianAdapter(aty, result.laberList,"");
		grid_bqtype.setAdapter(adapter);
		btn_image_right.setText("确定");
		isbtnRight=false;
	}

	/**
	 * 用户发布文章
	 */
	private void httpAddArtSubmit() {
		String contexts = "";
		String title=et_title.getText().toString();
		if(TextUtils.isEmpty(title)){
			ToastUtil.showShort(aty, "您还没有输入标题");
			return;
		}
		String context=edit_context.getText().toString();
		if(TextUtils.isEmpty(context)){
			ToastUtil.showShort(aty, "您还没有输入内容");
			return;
		}
		contexts+=context;
		for (int i = 0; i < listBase.size(); i++) {
			if(listBase.get(i).type==1){
				contexts+=listBase.get(i).editText.getText().toString();
			}else if(listBase.get(i).type==2){
				contexts+=listBase.get(i).url;
			}
		}
		if(TextUtils.isEmpty(labers)){
			ToastUtil.showShort(aty, "您还没有选择标签");
			return;
		}
		String artimgs="";
		if(listUrl.size()!=0){
			for (int i = 0; i <listUrl.size(); i++) {
				artimgs+=listUrl.get(i)+",";
			}
		}
//		if(adapter!=null){
//			for (int i = 0; i <adapter.getLaberVos().size(); i++) {
//				if(adapter.getLaberVos().get(i).laderBoolean==true){
//					labers+=adapter.getLaberVos().get(i).laberId+",";
//				}
//			}
//		}

		article articleS=new article();
		articleS.artMsg=contexts;
		articleS.artTitle=title;
		articleS.labers=labers;
		if(TextUtils.isEmpty(artimgs)){
			articleS.artimgs="";
		}else{
			articleS.artimgs=artimgs.substring(0,artimgs.length()-1);
		}
		HttpParams params = new HttpParams();
//		params.put("userId", new DBManager(aty).query().get(0).userId);// 所属用户ID
		params.put("artMsg", articleS.artMsg);//文章内容
		params.put("artTitle", 	articleS.artTitle);//文章标题
		params.put("artImgs", articleS.artimgs);//图片地址集合
		params.put("labers", articleS.labers);//标签ID集合
		params.put("artAnonymousStatus", Bradio?"Y":"N");// 匿名字段
		AppHttps.HttpPost(this,HttpInterface.ADD_ARTSUBMIT, params,
				new AppHttpCallBack<Object>(Object.class, aty) {
					@Override
					public void onSuccess(Object result) {
						labers="";
						et_title.setText("");
						edit_context.setText("");
						text_biaoq.setText("");
						ll_add_image.removeAllViews();
						listBase.clear();
						image_bqtype.setImageDrawable(getResources().getDrawable(R.mipmap.biaoqian_backgroud));
						ToastUtil.showShort(aty, "投稿信息已发布");
						Intent intent=new Intent(aty,SelfUserTwoActivity.class);
						startActivity(intent);
						finish();
					}

					@Override
					public void onFailures(int errorCode, String errorMsg) {
						ToastUtil.showShort(aty, errorMsg);
					}
				});
	}
//	@Override
//	public boolean onKeyDown(int keyCode, KeyEvent event) {
//		if (keyCode == KeyEvent.KEYCODE_BACK) {
//			if(ll_emotion_dashboard.getVisibility()== View.VISIBLE){
//				Message msg=new Message();
//				handler.sendMessageDelayed(msg, 0);
//			}else{
//				finish();
//			}
//			return false;
//		}
//		return super.onKeyDown(keyCode, event);
//
//	}
	/**
	 * 软键盘消失
	 */
	private void stopIm() {
		if(ll_emotion_dashboard.getVisibility()==View.VISIBLE){
			ll_emotion_dashboard.setVisibility(View.GONE);
		}else{
			ll_emotion_dashboard.setVisibility(View.VISIBLE);
		}
//		View v = getWindow().getDecorView();
//		InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//		Message msg=new Message();
//		if (manager.isActive()) {
//			manager.hideSoftInputFromWindow(v.getWindowToken(), 0);
//			handler.sendMessageDelayed(msg, 500);
//		}else{
//			handler.sendMessageDelayed(msg, 0);
//		}


	}
	Handler handler=new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			// 隐藏或显示表情面板
//			if(ll_emotion_dashboard.getVisibility()== View.VISIBLE){
//				TranslateAnimation translate = new TranslateAnimation(
//						Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
//						Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.78f);
//				translate.setDuration(500);
//				ll_photo_bq.startAnimation(translate);
//				translate.setAnimationListener(new AnimationListener() {
//					@Override
//					public void onAnimationStart(Animation arg0) {
//					}
//					@Override
//					public void onAnimationRepeat(Animation arg0) {
//					}
//					@Override
//					public void onAnimationEnd(Animation arg0) {
//						ll_emotion_dashboard.setVisibility(View.GONE);
//					}
//				});
//
//			}else if(ll_emotion_dashboard.getVisibility()== View.GONE){
//				TranslateAnimation translate = new TranslateAnimation(
//						Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
//						Animation.RELATIVE_TO_SELF, 0.78f, Animation.RELATIVE_TO_SELF, 0);
//				translate.setDuration(500);
//				ll_photo_bq.startAnimation(translate);
//				translate.setAnimationListener(new AnimationListener() {
//					@Override
//					public void onAnimationStart(Animation arg0) {
			ll_emotion_dashboard.setVisibility(View.VISIBLE);
//					}
//					@Override
//					public void onAnimationRepeat(Animation arg0) {
//					}
//					@Override
//					public void onAnimationEnd(Animation arg0) {
//					}
//				});
//			}

		}
	};
	//	@Override
//	public boolean onKeyDown(int keyCode, KeyEvent event) {
//		if (keyCode == KeyEvent.KEYCODE_BACK) {
//			return false;
//		}
//		return super.onKeyDown(keyCode, event);
//	}
	public class AppDialog {
		private ProgressDialog progressDialog;
		public AppDialog(Activity activity) {
//			OnKeyListener keylistener = new DialogInterface.OnKeyListener() {
//				public boolean onKey(DialogInterface dialog, int keyCode,
//						KeyEvent event) {
//					if (keyCode == KeyEvent.KEYCODE_BACK
//							&& event.getRepeatCount() == 0) {
//						return true;
//					} else {
//						return false;
//					}
//				}
//			};
			// this表示该对话框是针对当前Activity的
			progressDialog = new ProgressDialog(activity);
			// 设置进度条风格STYLE_SPINNER
			progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			progressDialog.setMessage("上传图片中");
//			progressDialog.setOnKeyListener(keylistener);
			progressDialog.setCanceledOnTouchOutside(false);
			progressDialog.onStart();
		}

		public void showDialog() {
			progressDialog.show();
		}

		public void dismissDialog() {
			progressDialog.dismiss();
		}
	}
}

